package com.hm.health.broadcast;

import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;


public class BlueToothBroadcastReceiver extends BroadcastReceiver {

    private final static String TAG = "BTBroadcastReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "receive a bluetooth broadcast");

        if (intent.getAction().equals(BluetoothDevice.ACTION_ACL_CONNECTED)) {

            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            Log.d(TAG, "connect bluetooth device name:" + device.getName() + " bluetooth device address:" + device.getAddress());

        } else if (intent.getAction().equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {

            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            Log.d(TAG, "disconnect bluetooth device name:" + device.getName() + " bluetooth device address:" + device.getAddress());

        } else {

            Log.d(TAG, "intent ignore");

        }

    }
}
